package com.cn.kabalifeuser.ui.service.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cn.kabalifeuser.R;
import com.cn.kabalifeuser.ui.service.bean.BusinessListBean;
import com.cn.kabalifeuser.utils.GlideUtil;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.flyco.roundview.RoundTextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 晓林 on 2020/9/3.
 * function:
 */
public class RecommendAdapter extends BaseQuickAdapter<BusinessListBean.ResultBean.DataBean, BaseViewHolder> {
    public RecommendAdapter(int layoutResId, @Nullable List<BusinessListBean.ResultBean.DataBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final BusinessListBean.ResultBean.DataBean item) {
//        if (helper.getPosition() == 0) {
//            helper.setGone(R.id.layout_1, true);
//            helper.setGone(R.id.layout_2, false);
//            GlideUtil.ImageLoad(this.mContext, item.getCover_url(), helper.getView(R.id.cover_url));
//            helper
//                    .setText(R.id.title, item.getTitle())
//                    .setText(R.id.tv_address_info, item.getAddress_info())
//            ;
//            TextView textView = helper.getView(R.id.tv_juli);
//            if (!TextUtils.isEmpty(item.getJuli())) {
//                textView.setVisibility(View.VISIBLE);
//                helper.setText(R.id.tv_juli, item.getJuli());
//            } else textView.setVisibility(View.GONE);
//            LoggerUtils.e("距11离：" + item.getJuli());
//
//            String fraction = item.getFraction();
//            ImageView xx1 = helper.getView(R.id.img_xx_1);
//            ImageView xx2 = helper.getView(R.id.img_xx_2);
//            ImageView xx3 = helper.getView(R.id.img_xx_3);
//            ImageView xx4 = helper.getView(R.id.img_xx_4);
//            ImageView xx5 = helper.getView(R.id.img_xx_5);
//            if (fraction.equals("5.0")) {
//                xx1.setImageResource(R.drawable.xx_true);
//                xx2.setImageResource(R.drawable.xx_true);
//                xx3.setImageResource(R.drawable.xx_true);
//                xx4.setImageResource(R.drawable.xx_true);
//                xx5.setImageResource(R.drawable.xx_true);
//            } else if (fraction.equals("4.5")) {
//                xx1.setImageResource(R.drawable.xx_true);
//                xx2.setImageResource(R.drawable.xx_true);
//                xx3.setImageResource(R.drawable.xx_true);
//                xx4.setImageResource(R.drawable.xx_true);
//                xx5.setImageResource(R.drawable.xx);
//            } else if (fraction.equals("4.0")) {
//                xx1.setImageResource(R.drawable.xx_true);
//                xx2.setImageResource(R.drawable.xx_true);
//                xx3.setImageResource(R.drawable.xx_true);
//                xx4.setImageResource(R.drawable.xx_true);
//                xx5.setImageResource(R.drawable.xx_false);
//            } else if (fraction.equals("3.5")) {
//                xx1.setImageResource(R.drawable.xx_true);
//                xx2.setImageResource(R.drawable.xx_true);
//                xx3.setImageResource(R.drawable.xx_true);
//                xx4.setImageResource(R.drawable.xx);
//                xx5.setImageResource(R.drawable.xx_false);
//            } else if (fraction.equals("3.0")) {
//                xx1.setImageResource(R.drawable.xx_true);
//                xx2.setImageResource(R.drawable.xx_true);
//                xx3.setImageResource(R.drawable.xx_true);
//                xx4.setImageResource(R.drawable.xx_false);
//                xx5.setImageResource(R.drawable.xx_false);
//            } else if (fraction.equals("2.5")) {
//                xx1.setImageResource(R.drawable.xx_true);
//                xx2.setImageResource(R.drawable.xx_true);
//                xx3.setImageResource(R.drawable.xx);
//                xx4.setImageResource(R.drawable.xx_false);
//                xx5.setImageResource(R.drawable.xx_false);
//            } else if (fraction.equals("2.0")) {
//                xx1.setImageResource(R.drawable.xx_true);
//                xx2.setImageResource(R.drawable.xx_true);
//                xx3.setImageResource(R.drawable.xx_false);
//                xx4.setImageResource(R.drawable.xx_false);
//                xx5.setImageResource(R.drawable.xx_false);
//            } else if (fraction.equals("1.5")) {
//                xx1.setImageResource(R.drawable.xx_true);
//                xx2.setImageResource(R.drawable.xx);
//                xx3.setImageResource(R.drawable.xx_false);
//                xx4.setImageResource(R.drawable.xx_false);
//                xx5.setImageResource(R.drawable.xx_false);
//            } else if (fraction.equals("1.0")) {
//                xx1.setImageResource(R.drawable.xx_true);
//                xx2.setImageResource(R.drawable.xx_false);
//                xx3.setImageResource(R.drawable.xx_false);
//                xx4.setImageResource(R.drawable.xx_false);
//                xx5.setImageResource(R.drawable.xx_false);
//            } else if (fraction.equals("0.5")) {
//                xx1.setImageResource(R.drawable.xx);
//                xx2.setImageResource(R.drawable.xx_false);
//                xx3.setImageResource(R.drawable.xx_false);
//                xx4.setImageResource(R.drawable.xx_false);
//                xx5.setImageResource(R.drawable.xx_false);
//            } else {
//                xx1.setImageResource(R.drawable.xx_false);
//                xx2.setImageResource(R.drawable.xx_false);
//                xx3.setImageResource(R.drawable.xx_false);
//                xx4.setImageResource(R.drawable.xx_false);
//                xx5.setImageResource(R.drawable.xx_false);
//            }
//
//            List<String> mListStr = new ArrayList<>();
//            for (int i = 0; i < item.getServices().size(); i++) {
//                mListStr.add(item.getServices().get(i).getTitle());
//            }
//            RecyclerView rv_type_list = helper.getView(R.id.rv_type_list);
//            LinearLayoutManager layoutManager1 = new LinearLayoutManager(this.mContext);
//            layoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);
//            layoutManager1.setSmoothScrollbarEnabled(true);
//            layoutManager1.setAutoMeasureEnabled(true);
//            rv_type_list.setLayoutManager(layoutManager1);
//            rv_type_list.setNestedScrollingEnabled(false);
//            ServicesTypeTitleAdapter servicesTypeTitleAdapter = new ServicesTypeTitleAdapter(R.layout.list_item_type, mListStr);
//            //给RecyclerView设置适配器
//            rv_type_list.setAdapter(servicesTypeTitleAdapter);
//        } else {
            helper.setGone(R.id.layout_1, false);
            helper.setGone(R.id.layout_2, true);
            GlideUtil.ImageLoad(this.mContext, item.getCover_url(), helper.getView(R.id.cover_url_2));
            helper
                    .setText(R.id.title_2, item.getTitle())
                    .setText(R.id.tv_address_info_2, item.getAddress_info())
                    .setText(R.id.tv_order_count, "单量：" + item.getOrder_count())
            ;
            TextView textView = helper.getView(R.id.tv_juli_2);
            if (!TextUtils.isEmpty(item.getJuli())) {
                textView.setVisibility(View.VISIBLE);
                helper.setText(R.id.tv_juli_2, item.getJuli());
            } else textView.setVisibility(View.GONE);
            String fraction = item.getFraction();
            ImageView xx1 = helper.getView(R.id.img_xx_1_2);
            ImageView xx2 = helper.getView(R.id.img_xx_2_2);
            ImageView xx3 = helper.getView(R.id.img_xx_3_2);
            ImageView xx4 = helper.getView(R.id.img_xx_4_2);
            ImageView xx5 = helper.getView(R.id.img_xx_5_2);
            if (fraction.equals("5.0")) {
                xx1.setImageResource(R.drawable.xx_true);
                xx2.setImageResource(R.drawable.xx_true);
                xx3.setImageResource(R.drawable.xx_true);
                xx4.setImageResource(R.drawable.xx_true);
                xx5.setImageResource(R.drawable.xx_true);
            } else if (fraction.equals("4.5")) {
                xx1.setImageResource(R.drawable.xx_true);
                xx2.setImageResource(R.drawable.xx_true);
                xx3.setImageResource(R.drawable.xx_true);
                xx4.setImageResource(R.drawable.xx_true);
                xx5.setImageResource(R.drawable.xx);
            } else if (fraction.equals("4.0")) {
                xx1.setImageResource(R.drawable.xx_true);
                xx2.setImageResource(R.drawable.xx_true);
                xx3.setImageResource(R.drawable.xx_true);
                xx4.setImageResource(R.drawable.xx_true);
                xx5.setImageResource(R.drawable.xx_false);
            } else if (fraction.equals("3.5")) {
                xx1.setImageResource(R.drawable.xx_true);
                xx2.setImageResource(R.drawable.xx_true);
                xx3.setImageResource(R.drawable.xx_true);
                xx4.setImageResource(R.drawable.xx);
                xx5.setImageResource(R.drawable.xx_false);
            } else if (fraction.equals("3.0")) {
                xx1.setImageResource(R.drawable.xx_true);
                xx2.setImageResource(R.drawable.xx_true);
                xx3.setImageResource(R.drawable.xx_true);
                xx4.setImageResource(R.drawable.xx_false);
                xx5.setImageResource(R.drawable.xx_false);
            } else if (fraction.equals("2.5")) {
                xx1.setImageResource(R.drawable.xx_true);
                xx2.setImageResource(R.drawable.xx_true);
                xx3.setImageResource(R.drawable.xx);
                xx4.setImageResource(R.drawable.xx_false);
                xx5.setImageResource(R.drawable.xx_false);
            } else if (fraction.equals("2.0")) {
                xx1.setImageResource(R.drawable.xx_true);
                xx2.setImageResource(R.drawable.xx_true);
                xx3.setImageResource(R.drawable.xx_false);
                xx4.setImageResource(R.drawable.xx_false);
                xx5.setImageResource(R.drawable.xx_false);
            } else if (fraction.equals("1.5")) {
                xx1.setImageResource(R.drawable.xx_true);
                xx2.setImageResource(R.drawable.xx);
                xx3.setImageResource(R.drawable.xx_false);
                xx4.setImageResource(R.drawable.xx_false);
                xx5.setImageResource(R.drawable.xx_false);
            } else if (fraction.equals("1.0")) {
                xx1.setImageResource(R.drawable.xx_true);
                xx2.setImageResource(R.drawable.xx_false);
                xx3.setImageResource(R.drawable.xx_false);
                xx4.setImageResource(R.drawable.xx_false);
                xx5.setImageResource(R.drawable.xx_false);
            } else if (fraction.equals("0.5")) {
                xx1.setImageResource(R.drawable.xx);
                xx2.setImageResource(R.drawable.xx_false);
                xx3.setImageResource(R.drawable.xx_false);
                xx4.setImageResource(R.drawable.xx_false);
                xx5.setImageResource(R.drawable.xx_false);
            } else {
                xx1.setImageResource(R.drawable.xx_false);
                xx2.setImageResource(R.drawable.xx_false);
                xx3.setImageResource(R.drawable.xx_false);
                xx4.setImageResource(R.drawable.xx_false);
                xx5.setImageResource(R.drawable.xx_false);
            }

            List<String> mListStr = new ArrayList<>();
            for (int i = 0; i < item.getServices().size(); i++) {
                mListStr.add(item.getServices().get(i).getTitle());
            }
            RecyclerView rv_type_list = helper.getView(R.id.rv_type_list_2);
            LinearLayoutManager layoutManager1 = new LinearLayoutManager(this.mContext);
            layoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);
            layoutManager1.setSmoothScrollbarEnabled(true);
            layoutManager1.setAutoMeasureEnabled(true);
            rv_type_list.setLayoutManager(layoutManager1);
            rv_type_list.setNestedScrollingEnabled(false);
            ServicesTypeTitleAdapter servicesTypeTitleAdapter = new ServicesTypeTitleAdapter(R.layout.list_item_type, mListStr);
            //给RecyclerView设置适配器
            rv_type_list.setAdapter(servicesTypeTitleAdapter);


    }
}
